<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增会议记录')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-record-add">
            <div class="form-group">
                <label class="col-sm-3 control-label">所属小组：</label>
                <div class="col-sm-8">
                    <input name="deptId" class="form-control" type="hidden" id="treeId" >
                    <div class="input-group">
                        <input name="deptName" onclick="selectDeptTree()" id="treeName" type="text"
                               placeholder="请选择小组" class="form-control" required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">会议标题：</label>
                <div class="col-sm-8">
                    <input name="recordTitle" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">记录时间：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input id="recordTime" name="recordTime" class="form-control" type="text" th:value="${recordTime}" required >
                    </div>

                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">会议内容：</label>
                <div class="col-sm-8">
                    <input id="recordContent" name="recordContent" class="form-control" type="hidden" >
                    <div class="summernote" ></div>
                </div>
            </div>
            <!--<div class="form-group">-->
                <!--<label class="col-sm-3 control-label">图片：</label>-->
                <!--<div class="col-sm-8">-->
                    <!--<input id="recordImg" name="recordImg" class="form-control" type="hidden">-->
                    <!--<div class="file-loading">-->
                        <!--<input id="fileinput-demo-1" type="file" name="file" data-min-file-count="1" multiple>-->
                    <!--</div>-->
                <!--</div>-->
            <!--</div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">视频：</label>
                <div class="col-sm-8">
                    <input id="recordVideo" name="recordVideo" class="form-control" type="hidden">
                    <div class="file-loading">
                        <input id="fileinput-video" type="file" name="file" data-min-file-count="1"  multiple >
                    </div>
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: summernote-js"/>
    <script type="text/javascript">
        var prefix = ctx + "module/record"
        $("#form-record-add").validate({
            focusCleanup: true
        });

        layui.use('laydate', function() {
            var laydate = layui.laydate;
            laydate.render({
                elem: '#recordTime',
                type: 'datetime',
                trigger: 'click'
            });
        });

        $('.summernote').summernote({
            placeholder: '请输入内容',
            height: 250,
            lang: 'zh-CN',
            followingToolbar: false,
            callbacks: {
                onImageUpload: function (files) {
                    sendFile(files[0], this);
                }
            }
        });

        // 上传文件
        function sendFile(file, obj) {
            var data = new FormData();
            data.append("file", file);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function (result) {
                    if (result.code == web_status.SUCCESS) {
                        $(obj).summernote('editor.insertImage', result.url, result.fileName);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function (error) {
                    $.modal.alertWarning("图片上传失败。");
                }
            });
        }


        function submitHandler() {
            if ($.validate.form()) {
                var sHTML = $('.summernote').summernote('code');
                $("#recordContent").val(sHTML);
                $.operate.save(prefix + "/add", $('#form-record-add').serialize());
            }
        }

        /*-新增-选择部门树*/
        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero) {
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
            }
        }

        //上传图片
        var uploadUrl = ctx + "common/uploadImage_QiNiu";

        var imgArr= new Array();
        $(document).ready(function () {
            $("#fileinput-demo-1").fileinput({
                'theme': 'explorer-fas',
                'uploadUrl': uploadUrl,
                overwriteInitial: false,
                allowedFileExtensions : ['jpg', 'png','gif'],//接收的文件后缀
                initialPreviewAsData: true,
                initialPreview: []
            });

            // 上传成功回调
            $("#fileinput-demo-1").on("fileuploaded", function (event, data, previewId, index) {
                var imgStr = data.response.data.src;
                imgArr.push(imgStr);
                var img = imgArr.join(",");
                $("#recordImg").val(img);
            });
        });

        var videoUrl = ctx + "common/uploadVideo_QiNiu";
        var videoArr= new Array();
        //上传视频
        $(document).ready(function () {

            $("#fileinput-video").fileinput({
                'theme': 'explorer-fas',
                'uploadUrl': videoUrl,
                overwriteInitial: false,
                allowedFileExtensions : [ "mp4","avi","dat","3gp","mov","rmvb"],
                initialPreviewAsData: true,
                initialPreview: []
            });

            // 上传成功回调
            $("#fileinput-video").on("fileuploaded", function (event, data, previewId, index) {
                console.log(data);
                if(data.response.code=="0"){
                    var videoStr = data.response.data.src;
                    videoArr.push(videoStr);
                    var video = videoArr.join(",");
                    console.log("***"+video);
                    $("#recordVideo").val(video);
                } else {
                    $.modal.error(data.response.msg);
                }


            });
        });


    </script>
</body>
</html>